package com.qiya.LiaoDa.ZViewPagerAdapter;

import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.qiya.LiaoDa.Fragment.ShouYeFragment;
import com.qiya.LiaoDa.Fragment.WoDeFragment;
import com.qiya.LiaoDa.Fragment.DCFragment;
import com.qiya.LiaoDa.Fragment.XYZXFragment;
import com.qiya.LiaoDa.MainActivity;

public class ZViewPagerAdapter extends FragmentPagerAdapter {

    private final int PAGER_COUNT = 4;
    private ShouYeFragment myFragment1;
    private DCFragment myFragment2;
    private XYZXFragment myFragment3;
    private WoDeFragment myFragment4;


    public ZViewPagerAdapter(FragmentManager fm) {
        super(fm);
        myFragment1 = new ShouYeFragment();
        myFragment2 = new DCFragment();
        myFragment3 = new XYZXFragment();
        myFragment4 = new WoDeFragment();
    }

    @Override
    public int getCount() {
        return PAGER_COUNT;
    }

    @Override
    public Object instantiateItem(ViewGroup vg, int position) {
        return super.instantiateItem(vg, position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        System.out.println("position Destory" + position);
        super.destroyItem(container, position, object);
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case MainActivity.PAGE_ONE:
                fragment = myFragment1;
                break;
            case MainActivity.PAGE_TWO:
                fragment = myFragment2;
                break;
            case MainActivity.PAGE_THREE:
                fragment = myFragment3;
                break;
            case MainActivity.PAGE_FOUR:
                fragment = myFragment4;
                break;
        }
        return fragment;
    }


}